<template>
  <div class="x-switch" :class="{ active: value, inactive: !value }" @click="handleClick">
    <div class="round" :class="{ transform: value }"></div>
  </div>
</template>

<script>
  export default {
    name: 'XSwitch',
    props: {
      value: {
        type: Boolean,
        default: false,
      },
    },
    data() {
      return {
        MyValue: this.value,
      }
    },
    methods: {
      handleClick() {
        this.MyValue = !this.MyValue
        this.$emit('input', this.MyValue)
      },
    },
  }
</script>

<style lang="scss" scoped>
  @import '../config.scss';
  .x-switch {
    box-sizing: border-box;
    width: 51px;
    height: 31px;
    padding: 4px;
    border-radius: 18px;
    transform: color 0.3s ease;

    .round {
      width: 23px;
      height: 23px;
      border-radius: 50%;
      background-color: #fff;
      transition: transform 0.3s ease;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    }
  }
  .active {
    background-color: $primary-color;
  }
  .inactive {
    background-color: rgba(206, 213, 224, 1);
  }
  .transform {
    transform: translateX(20px);
  }
</style>
